package free_practice.work;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author fangzhiyi
 * @version 1.0
 * @date 2025/3/22 14:07
 * @description
 */
public class Dao {
    ArrayList<Student> stu = new ArrayList<Student>();
    ArrayList<Teacher> teachers = new ArrayList<Teacher>();
    public static final Scanner INPUT = new Scanner(System.in);

    {
        stu.add(new Student(101,"南风","男",18,80,"学生"));
        stu.add(new Student(102,"小桐","男",19,92,"历史课代表"));
        stu.add(new Student(103,"方知意","男",18,90,"数学课代表"));
        stu.add(new Student(104,"小帅","男",18,45,"学生"));
        stu.add(new Student(105,"初雪","女",18,62,"英语课代表"));
        stu.add(new Student(106,"王子凯","男",16,30,"语文课代表"));
        stu.add(new Student(107,"高欣欣","女",17,85,"物理课代表"));

        teachers.add(new Teacher("柳婉莹","女",25,"数学"));
        teachers.add(new Teacher("高阳","男",22,"语文"));
        teachers.add(new Teacher("黄文","男",32,"历史"));
        teachers.add(new Teacher("青灵","女",25,"英语"));
        teachers.add(new Teacher("万思思","女",21,"物理"));
    }
        //打印学生的所有信息
    public void findStu(){
        for (int i = 0; i < stu.size(); i++) {
            System.out.println(stu.get(i));
        }
    }

    public void addStu(){
        System.out.println("请输入学号:");
        int id = INPUT.nextInt();
        System.out.println("请输入姓名");
        String name = INPUT.next();
        System.out.println("请输入性别");
        String sex = INPUT.next();
        System.out.println("请输入年龄");
        int age = INPUT.nextInt();
        System.out.println("请输入成绩");
        double score  = INPUT.nextDouble();
        System.out.println("请输入官职");
        String posts = INPUT.next();
        stu.add(new Student(id,name,sex,age,score,posts));
    }
        //根据学号来对学生的成绩进行修改
    public void setScore(){
        System.out.println("请输入要修改成绩的学生的学号:");
        int id = INPUT.nextInt();
        for (int i = 0; i < stu.size(); i++) {
            if (id==stu.get(i).getId()){
                System.out.println("请输入修改后的成绩");
                double score = INPUT.nextDouble();
               stu.get(i).setScore(score);
                System.out.println(stu.get(i));
            }
        }
    }

    //打印成绩优良的学生信息
    public void printScore(){
        for (int i = 0; i < stu.size(); i++) {
            if (stu.get(i).getScore()>=80){
                System.out.println(stu.get(i));
            }
        }
    }

    //查询某个科目的老师的信息
    public void findTeacher(){
        System.out.println("请输入科目");
        String subjects = INPUT.next();
        for (int i = 0; i < teachers.size(); i++) {
            if (subjects.equals(teachers.get(i).getSubjects())){
                System.out.println(teachers.get(i));
            }
        }
    }
    //打印需要补考的学生(成绩<60),
    public void printStu(){
        int count =0;
        for (int i = 0; i < stu.size(); i++) {
            if (stu.get(i).getScore()<60){
                System.out.println("需要补考的学生"+stu.get(i));
                count++;
            }
        }
        System.out.println("需要补考的学生一共有"+count+"位");
    }

    //根据姓名删除学生并打印删除后的所有学生信息
    public void delStu(){
        String name = INPUT.next();
        for (int i = 0; i < stu.size(); i++) {
            if (name.equals(stu.get(i).getName())){
                System.out.println("请问是否要删除(y/n)");
                String num = INPUT.next();
                if (num.equals("y")){
                    stu.remove(i);
                }else {
                    return;
                }
            }
        }

        //打印删除后的所有学生信息
        for (int i = 0; i < stu.size(); i++) {
            System.out.println(stu.get(i));
        }
    }
}
